package logic

import (
	"context"
	"encoding/json"

	"lottery-zero/internal/model"
	"lottery-zero/internal/svc"
	"lottery-zero/internal/types"

	"github.com/tal-tech/go-zero/core/logx"
)

type LottodeletebetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLottodeletebetLogic(ctx context.Context, svcCtx *svc.ServiceContext) LottodeletebetLogic {
	return LottodeletebetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *LottodeletebetLogic) Lottodeletebet(req types.LottoTicksDeleteReq, userId string) (*types.CodeReply, error) {
	userInt, _ := json.Number(userId).Int64()
	l.svcCtx.PGDB.Where(&model.UserLotteryTicket{ID: uint(req.ID), UserID: uint(userInt)}).Delete(&model.UserLotteryTicket{})
	return &types.CodeReply{Code: 200, Msg: "success"}, nil
}
